<?php
$menumark = 'hotelimg';

switch ($act) {
    //#####################@ 修改分类 @#####################//
    case 'edit':
        if (isGet()) {

            $hotelimgcate = $db->pe_selectall('hotelimgcate');
            $hotelimg = $db->pe_select('hotelimg', array('hotelimg_id' => $_g_id));
            include(pe_tpl('hotelimg_edit.html'));
        } else if (isPost()) {

            if ($_FILES['hotel_img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['hotel_img']);
                $_p_info['hotelimg_img'] = $upload->filehost;
            }
            $result = $db->pe_update("hotelimg", array('hotelimg_id' => $_g_id), $_p_info);

            if ($result) {
                pe_success('修改成功');
            } else {
                pe_error('修改失败');
            }

        }
        break;

    case 'add':
        if (isGet()) {

            $hotelimgcate = $db->pe_selectall('hotelimgcate');
            include(pe_tpl('hotelimg_add.html'));
        } else if (isPost()) {

            if ($_FILES['hotel_img']['size']) {
                pe_lead('include/class/upload.class.php');
                $upload = new upload($_FILES['hotel_img']);
                $_p_info['hotelimg_img'] = $upload->filehost;
            }
            $result = $db->pe_insert("hotelimg", $_p_info);

            if ($result) {
                pe_success('添加成功', 'admin.php?mod=hotelimg&act=add');
            } else {
                pe_error('添加失败');
            }

        }

        include(pe_tpl('hotelimg_add.html'));
        break;

    case 'del':
        if ($db->pe_delete('hotelimg', array('hotelimg_id' => $_g_id))) {
            pe_success('删除成功');
        } else {
            pe_error('删除失败');
        }
        include(pe_tpl('hotelimg_list.html'));
        break;

    //#####################@ 分类列表 @#####################//
    default :
        if(isGet()){
            $sql = 'select ho.hotelimg_id,ho.hotelimg_img,ho.hotelimg_category_id,ho.hotelimg_order,ho.hotelimg_state,hc.category_name,group_concat(ho.hotelimg_img) as hotelimg,group_concat(ho.hotelimg_order) as hotelorder from wxgg_hotelimg as ho join wxgg_hotelimgcate as hc where ho.hotelimg_category_id = hc.category_id group by ho.hotelimg_category_id';

            $hotelimg = $db->sql_selectall($sql);
            foreach ($hotelimg as $k => $v){
                $hotelimg[$k]['hotelimg'] = explode(',',$v['hotelimg']);
                $hotelimg[$k]['hotelorder'] = explode(',',$v['hotelorder']);
            }


//            mp($hotelimg);exit;
            include(pe_tpl('hotelimg_list.html'));
        }else if(isPost()){
            foreach ($_p_info as $v){
                $db->pe_update('hotelimg',array('hotelimg_id'=>$v['hotelimg_id']),array('hotelimg_order'=>$v['hotelimg_order']));
            }
            pe_success('更新成功');
        }


        break;
}
?>